package com.etlmaster.executor.steps.sql;

import java.util.HashMap;
import java.util.Map;

import com.etlmaster.executor.Step;
import com.etlmaster.executor.StepMeta;
import com.etlmaster.executor.annotation.StepInstruction;
import com.etlmaster.executor.utils.DataCollectionUtils;
import com.etlmaster.executor.utils.DpExecutorUtils;
import com.etlmaster.executor.utils.StepState;
import com.etlmaster.jdbc.JdbcTemplate;
/**
 * @author Wugf
 * @date 2016-03-08
 */
@StepInstruction("runStatsTable")
public class RunStatStep extends Step {

	private RunStatStepMeta meta;

	
	public RunStatStep(StepMeta meta) {
		super(meta);
		this.meta = (RunStatStepMeta) meta;

	}

	@Override
	protected int handle() {
		String runStat =  DataCollectionUtils.getProperties("db2.runstats");
		JdbcTemplate jdbc = new JdbcTemplate(meta.getDsName());
		Map data=new HashMap();
		data.put("tableName", meta.getTableName());
		runStat=DpExecutorUtils.variableSubstitution(runStat, data);
		meta.log("INFO","执行命令：{}",runStat);
		try{
			jdbc.update(runStat);
		}catch(Exception e){
			meta.log("INFO","runstats 表{}失败,{}",meta.getTableName(),e.getMessage());
			return StepState.RUNNING_FAILED;
		}
		return StepState.RUNNING_SUCCESSED;
	}

	@Override
	public boolean stop() {
		// TODO Auto-generated method stub
		return false;
	}

}
